package com.legal.aid.app.controller;

import com.legal.aid.app.domain.vo.LawyerVo;
import com.legal.aid.app.service.IAppLawyerService;
import com.legal.aid.common.core.controller.BaseController;
import com.legal.aid.common.core.domain.AjaxResult;
import com.legal.aid.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/app/lawyer")
public class AppLawyerController extends BaseController {

    @Autowired
    private IAppLawyerService appLawyerService;

    @GetMapping("/list")
    public TableDataInfo list(LawyerVo LawyerVo) {
        startPage();
        List<LawyerVo> list = appLawyerService.selectLawyerList(LawyerVo);
        return getDataTable(list);
    }

    /**
     * 返回补全内容
     * 
     * @param prefix
     * @return
     */
    @GetMapping("/suggestion")
    public AjaxResult getLawyerSuggestions(@RequestParam("key") String prefix) {
        List<String> list = appLawyerService.getLawyerSuggestions(prefix);
        return success(list);
    }

    /**
     * 查询律师
     */
    @GetMapping("/search")
    public TableDataInfo searchNews(@RequestParam("keyword") String keyword,
            @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
        startPage();
        List<LawyerVo> list = appLawyerService.searchLawyerByKeyword(keyword, pageNum, pageSize);
        return getDataTable(list);
    }

    @PutMapping("/updateLawyerToEs")
    public AjaxResult updateLawyerTOEs() {
        return appLawyerService.updateLawyerToEs() > 0 ? AjaxResult.success() : AjaxResult.error("news数据更新到es失败", 502);
    }

    @GetMapping("/expertise/{expertiseId}")
    public AjaxResult list(@PathVariable("expertiseId") String expertiseId) {
        List<LawyerVo> list = appLawyerService.getLawyerListByExpertiseId(expertiseId);
        return AjaxResult.success(list);
    }

    /**
     * 获取律师详情
     */
    @GetMapping(value = "/detail/{lawyerId}")
    public AjaxResult getLawyerDetailByLawyerId(@PathVariable("lawyerId") String lawyerId) {
        return AjaxResult.success(appLawyerService.getLawyerDetailByLawyerId(lawyerId));
    }

    /**
     * 获取律师详情ByUserId
     */
    @GetMapping(value = "/detailByUserId/{userId}")
    public AjaxResult getLawyerDetailByUserId(@PathVariable("userId") String userId) {
        return AjaxResult.success(appLawyerService.getLawyerDetailByUserId(userId));
    }

    /**
     * 获取当前登录用户律师的关注列表
     *
     */
    @GetMapping("/attention")
    public AjaxResult selectAttentionNewsList() {
        List<LawyerVo> list = appLawyerService.selectAttentionLawyersVoList();
        return AjaxResult.success(list);
    }

}
